﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Microsoft.Win32;

namespace BoobyTrap
{
    public partial class frmConfig : Form
    {
        string pic_path;
        public frmConfig()
        {
            InitializeComponent();
        }
        private void frmConfig_Load(object sender, EventArgs e)
        {
            pictureBox1.Image = Program.conf.bg_img;
        }
        private void button2_Click(object sender, EventArgs e)
        {
            Stream myStream;
            Bitmap new_pic;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        new_pic = new Bitmap(myStream);
                        pic_path = openFileDialog1.FileName;
                        pictureBox1.Image = new_pic;
                    }
                }
                catch (System.BadImageFormatException ex)
                {
                    MessageBox.Show("Error: could not find image. Original error: " + ex.Message);
                }
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\BoobyTrap_Screensaver");
            if (key != null)
                Registry.CurrentUser.DeleteSubKeyTree("SOFTWARE\\BoobyTrap_Screensaver");
            if (pic_path != null)
            {
                key = Registry.CurrentUser.CreateSubKey("SOFTWARE\\BoobyTrap_Screensaver");
                key.SetValue("img_path", pic_path);
            }
            Close();
        }
    }
}
